<?php
/*********************************
 * DECLARE SYSTEM CONFIGURATIONS *
 ********************************/
$time_start = microtime(true);

if( ! ini_get('date.timezone') )
{
   date_default_timezone_set('GMT');
}

// Define separators
defined('DS') || define('DS', DIRECTORY_SEPARATOR);
defined('PS') || define('PS', PATH_SEPARATOR);

// Define path to directories
defined('ROOT_DIR') || define('ROOT_DIR', str_replace(DS, '/', dirname(dirname(__FILE__)))); 
defined('APPLICATION_DIR') || define('APPLICATION_DIR', ROOT_DIR.'/application');
defined('DATA_DIR') || define('DATA_DIR', ROOT_DIR.'/data');
defined('LIBRARIES_DIR') || define('LIBRARIES_DIR', ROOT_DIR.'/libraries');
defined('PUBLIC_DIR') || define('PUBLIC_DIR', ROOT_DIR.'/public');

// Define domain name and protocols
defined('DOMAIN') || define('DOMAIN', $_SERVER['HTTP_HOST']);
defined('BASE_URL') || define('BASE_URL', 'http://'.DOMAIN);
defined('BASE_URL_SECURE') || define('BASE_URL_SECURE', 'https://'.DOMAIN);

// Ensure libraries/ is on include_path
set_include_path(implode(PS, array(realpath(LIBRARIES_DIR), get_include_path())));

/*******************
 * RUN APPLICATION *
 ******************/
// change the following paths if necessary
$yii=LIBRARIES_DIR.'/yii/yii.php';
$config=APPLICATION_DIR.'/config/main.php';

// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

require_once($yii);
Yii::createWebApplication($config)->run();

//debug
$time_end = microtime(true);
$time = $time_end - $time_start;

if(isset($_GET['debug']) && $_GET['debug'] == true)
	echo '<div style="display:block;top:0;left:0;z-index:100000;color:red;clear:both;width:100%;text-align:center;">Execution time: '.round($time, 3).'ms --- Memory usage: '.round(memory_get_usage()/1024/1024, 3).'mb --- Memory peak usage: '.round(memory_get_peak_usage(true)/1024/1024, 3).'mb</div>';	

function o($var){
	echo '<pre>'; var_dump($var); die;
}
